import {
	getDicts
} from '@/common/api.js'

const dictsMixin = {
	props: {
		dictTypes: {
			type: Array,
			default: () => []
		}
	},
	data() {
		return {
			dicts: {},
		};
	},
	created() {
		if (this.dictTypes && this.dictTypes.length) {
			this.dictTypes.forEach(type => {
				this.getDictsList(type)
			})
		}
	},
	methods: {
		async getDictsList(type) {
			if (!type) {
				console.error('dictsMixin: type is required')
				return
			}
			let res = await getDicts(type)
			this.$set(this.dicts, type, res.data || [])
		},
	}
}

export default dictsMixin